package edu.unlv.cs.ladders.entities;

import edu.unlv.cs.ladders.entities.Tournament;
import java.lang.SuppressWarnings;
import java.util.Calendar;
import javax.persistence.EntityManager;
import javax.persistence.Query;

privileged aspect Event_Roo_Finder {
    
    @SuppressWarnings("unchecked")
    public static Query Event.findEventsByDateOfEventGreaterThanEquals(Calendar dateOfEvent) {
        if (dateOfEvent == null) throw new IllegalArgumentException("The dateOfEvent argument is required");
        EntityManager em = Event.entityManager();
        Query q = em.createQuery("SELECT Event FROM Event AS event WHERE event.dateOfEvent >= :dateOfEvent");
        q.setParameter("dateOfEvent", dateOfEvent);
        return q;
    }
    
    @SuppressWarnings("unchecked")
    public static Query Event.findEventsByTournament(Tournament tournament) {
        if (tournament == null) throw new IllegalArgumentException("The tournament argument is required");
        EntityManager em = Event.entityManager();
        Query q = em.createQuery("SELECT Event FROM Event AS event WHERE event.tournament = :tournament");
        q.setParameter("tournament", tournament);
        return q;
    }
    
    @SuppressWarnings("unchecked")
    public static Query Event.findEventsByTournamentAndDateOfEventGreaterThanEquals(Tournament tournament, Calendar dateOfEvent) {
        if (tournament == null) throw new IllegalArgumentException("The tournament argument is required");
        if (dateOfEvent == null) throw new IllegalArgumentException("The dateOfEvent argument is required");
        EntityManager em = Event.entityManager();
        Query q = em.createQuery("SELECT Event FROM Event AS event WHERE event.tournament = :tournament AND event.dateOfEvent >= :dateOfEvent");
        q.setParameter("tournament", tournament);
        q.setParameter("dateOfEvent", dateOfEvent);
        return q;
    }
    
    @SuppressWarnings("unchecked")
    public static Query Event.findEventsByDateOfEventBetween(Calendar minDateOfEvent, Calendar maxDateOfEvent) {
        if (minDateOfEvent == null) throw new IllegalArgumentException("The minDateOfEvent argument is required");
        if (maxDateOfEvent == null) throw new IllegalArgumentException("The maxDateOfEvent argument is required");
        EntityManager em = Event.entityManager();
        Query q = em.createQuery("SELECT Event FROM Event AS event WHERE event.dateOfEvent BETWEEN :minDateOfEvent AND :maxDateOfEvent");
        q.setParameter("minDateOfEvent", minDateOfEvent);
        q.setParameter("maxDateOfEvent", maxDateOfEvent);
        return q;
    }
    
}
